import router from "@/router/index";
export default {
  namespaced: true,
  state() {
    return {
      routePath: "",
      tabList: [
        {
          path: "/",
          title: "首页",
          icon: "Home",
        },
      ], //快捷菜单列表
      tabPath: "/",
    };
  },
  mutations: {
    initRoutePathMut(state, path) {
      state.routePath = path;
    },
    tabAddMut(state, tabObj) {
      let { tabList } = state;
      state.tabPath = tabObj.path; //切换菜单激活效果
      for (let i = 0; i < tabList.length; i++) {
        if (tabObj.path == tabList[i].path) {
          return;
        }
      }

      state.tabList.push(tabObj);
    },
    tabDelMut(state, path) {
      let { tabList } = state;
      for (let i = 0; i < tabList.length; i++) {
        if (tabList[i].path == path) {
          state.tabPath = tabList[i - 1].path; //切换菜单激活效果
          router.push(tabList[i - 1].path);
          tabList.splice(i, 1);
          return;
        }
      }
    },
    initTabMut(state) {
      let list = localStorage.getItem("tabList-2206");
      let path = localStorage.getItem("tabPath-2206");
      if (list) {
        state.tabList = JSON.parse(list);
        state.tabPath = path;
      }
    },
    tabPathMut(state, path) {
      state.tabPath = path;
    },
  },
};
